#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
@author: yinzhuoqun
@site: http://zhuoqun.info/
@email: yin@zhuoqun.info
@time: 2019/9/5 15:26
"""
from django import forms
from django.forms.widgets import TextInput
from apps.blog.models import Article
from import_export.forms import ImportForm, ConfirmImportForm


class ArticleAdminForm(forms.ModelForm):
    test_field = forms.CharField(label="测试字段", help_text="请输入", required=False)

    class Meta:
        model = Article
        fields = '__all__'
        widgets = {
            "title": TextInput(attrs={"style": "width:45%;", "placeholder": "请输入标题"}),
        }


class AddInfoForm(forms.Form):
    select_choice = (
        ('1', '测试1'),
        ("2", "测试2"),
        ("3", "测试3"),
        ("4", "测试4"),
    )

    phone = forms.CharField(label="请输入接收的号码", help_text="请输入接收的号码", required=True,
                            widget=forms.TextInput(attrs={"style": "width:60%;"}))
    content = forms.CharField(label="请输入发送的内容", help_text="请输入发送的内容", required=False,
                              # widget=forms.Textarea,
                              widget=forms.TextInput(attrs={"style": "width:60%;"})
                              )
    test_select = forms.CharField(label="请选择接的受号码", help_text="请选择接受的号码", initial="in",
                                  widget=forms.RadioSelect(choices=select_choice, attrs={'class': 'form-control'}))
    test_select1 = forms.CharField(label="测试下拉框", help_text="测试下拉框",
                                   widget=forms.Select(choices=select_choice, attrs={'class': 'form-control'}))

    def clean_test_input(self):
        test_input = self.cleaned_data.get("test_input").strip()
        if len(test_input) < 11:
            raise forms.ValidationError("手机号码输入不正确")
